package com.leetcode.algorithm.y22.todo;

/**
 * 486. 预测赢家
 * 
 * https://leetcode.cn/problems/predict-the-winner/
 * 
 * @author jie.deng
 *
 */
class Question0486Solution01 {

	public boolean PredictTheWinner(int[] nums) {
		int len = nums.length;
		int diff = 0;
		int left = 0;
		int right = len - 1;
		int idx = 0;
		while (idx < len) {
			int num = 0;
			if (nums[left] < nums[right]) {
				num = nums[right--];
			} else {
				num = nums[left++];
			}
			if ((idx & 1) == 0) {
				diff += num;
			} else {
				diff -= num;
			}
			idx++;
		}
		return diff >= 0;
	}

}